<?php
/**
 * 合同管理数据库的Entity基础类
 */

namespace common\entities;


class ContractEntity extends BaseEntity
{

    /**
     * @return \yii\db\connection
     */
    public static function getDb()
    {
        return \Yii::$app->contractDB; //config/web中配置的链接
    }

    /**
     * 获取数据库当前时间截
     * @return int
     */
    public static function getDbNowTimestamp()
    {
        $db = self::getDb();
        $timestamp = $db->createCommand("SELECT UNIX_TIMESTAMP() AS `timestamp`")->queryScalar();//取数据库时间
        return $timestamp;
    }

    /**
     * 获取数据库当前时间(如2015-05-22 12:00:00)
     * @return string
     */
    public static function getDbNowDate()
    {
        $db = self::getDb();
        $timestamp = $db->createCommand("SELECT UNIX_TIMESTAMP() AS `timestamp`")->queryScalar();//取数据库时间
        return date("Y-m-d H:i:s", $timestamp);
    }
}